<?php

/**
 * This is the model class for table "emp_empresa".
 *
 * The followings are the available columns in table 'emp_empresa':
 * @property integer $id
 * @property string $nombre
 * @property string $glosa_pais_id
 * @property string $email
 * @property string $representante
 * @property string $ciudad
 * @property string $provincia
 *
 * The followings are the available model relations:
 * @property EmpArea[] $empAreas
 * @property EmpArticulo[] $empArticulos
 * @property EmpArticuloJer1[] $empArticuloJer1s
 * @property EmpClienteTipo[] $empClienteTipos
 * @property GlosaPais $glosaPais
 * @property EmpListaPrecio[] $empListaPrecios
 * @property EmpPersona[] $empPersonas
 * @property EmpSede[] $empSedes
 * @property EmpUsuario[] $empUsuarios
 */
class EmpEmpresa extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return EmpEmpresa the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'emp_empresa';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nombre, glosa_pais_id, email, representante', 'required'),
			array('nombre, email, representante, ciudad, provincia', 'length', 'max'=>45),
			array('glosa_pais_id', 'length', 'max'=>2),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, nombre, glosa_pais_id, email, representante, ciudad, provincia', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'empAreas' => array(self::HAS_MANY, 'EmpArea', 'emp_empresa_id'),
			'empArticulos' => array(self::HAS_MANY, 'EmpArticulo', 'emp_empresa_id'),
			'empArticuloJer1s' => array(self::HAS_MANY, 'EmpArticuloJer1', 'emp_empresa_id'),
			'empClienteTipos' => array(self::HAS_MANY, 'EmpClienteTipo', 'emp_empresa_id'),
			'glosaPais' => array(self::BELONGS_TO, 'GlosaPais', 'glosa_pais_id'),
			'empListaPrecios' => array(self::HAS_MANY, 'EmpListaPrecio', 'emp_empresa_id'),
			'empPersonas' => array(self::HAS_MANY, 'EmpPersona', 'emp_empresa_id'),
			'empSedes' => array(self::HAS_MANY, 'EmpSede', 'emp_empresa_id'),
			'empUsuarios' => array(self::HAS_MANY, 'EmpUsuario', 'emp_empresa_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nombre' => 'Nombre',
			'glosa_pais_id' => 'Glosa Pais',
			'email' => 'Email',
			'representante' => 'Representante',
			'ciudad' => 'Ciudad',
			'provincia' => 'Provincia',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nombre',$this->nombre,true);
		$criteria->compare('glosa_pais_id',$this->glosa_pais_id,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('representante',$this->representante,true);
		$criteria->compare('ciudad',$this->ciudad,true);
		$criteria->compare('provincia',$this->provincia,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}